package cn.sxt.oop;

/**
 * 测试String类
 */
public class StringTest {
    public static void main(String[] arge){
        String s1 = "core Java";
        String s2 = "Core Java";
        //提取下标为3的字符
        System.out.println(s1.charAt(3));
        //字符串的长度
        System.out.println(s2.length());
        //比较两个字符串是否相等
        System.out.println(s1.equals(s2));
        //比较两个字符串（忽略大小写）
        System.out.println(s1.equalsIgnoreCase(s2));
        //字符串s1中是否包含Java
        System.out.println(s1.indexOf("Java"));
        //字符串s1中是否包含apple
        System.out.println(s1.indexOf("apple"));
        //将s1中的空格替换成&
        String s = s1.replace(' ','&');
        System.out.println(s);

        s1 = "How are you?";
        //s1是否以How开头
        System.out.println(s1.startsWith("How"));
        //s1是否以you结尾
        System.out.println(s1.endsWith("you"));
        //提取子字符串：从下标4的开始到字符串结尾为止
        s = s1.substring(4);
        System.out.println(s);
        //提取子字符串：下标[4,7)不包括7
        s = s1.substring(4,7);
        System.out.println(s);
        //转小写
        s = s1.toLowerCase();
        System.out.println(s);
        //转大写
        s = s1.toUpperCase();
        System.out.println(s);
        //去除字符串首尾的空格。注意中间的空格不能去除
        s2 = "   How are you?     ";
        s = s2.trim();
        System.out.println(s);
        //因为String是不可变字符串，所以s2不变
        System.out.println(s2);

    }
}
